<?php
App::uses('Controller', 'Controller');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('ComponentCollection', 'Controller');
App::uses('GameComponent', 'Controller/Component');
App::uses ( 'CsvIterator', 'ZCommon' );

// A fake controller to test against
class TestGameController extends Controller {
	
}

class GameComponentTest extends CakeTestCase {
	public $GameComponent = null;
	public $Controller = null;

	public function setUp() {
		parent::setUp();
		// Setup our component and fake test controller
		$Collection = new ComponentCollection();
		$this->GameComponent = new GameComponent($Collection);
		$CakeRequest = new CakeRequest();
		$CakeResponse = new CakeResponse();
		$this->Controller = new TestGameController($CakeRequest, $CakeResponse);
		$this->GameComponent->startup($this->Controller);
	}

	/**
	 * @dataProvider provider
	 */
	public function testDoCheckWinner($price, $guess1, $guess2, $guess3, $guess4, $expected) {
		// Test our adjust method with different parameter settings
		
		$result = $this->GameComponent->doCheckWinner($price, $guess1, $guess2, $guess3, $guess4);
		$this->assertEquals($result, $expected);
		
	}
	
	
	public function provider() {
		$file = TMP . 'tests/testDoCheckWinner.csv';
		$arr_data = new CsvIterator ( $file );
		// convert iterator to array, remove null element, reindex
		$arr_data = array_values ( array_filter ( iterator_to_array ( $arr_data ) ) );
		// remove first element - for column title
		array_shift ( $arr_data );
		return $arr_data;
	}

	public function tearDown() {
		parent::tearDown();
		// Clean up after we're done
		unset($this->GameComponent);
		unset($this->Controller);
	}
}